#include<iostream> 
using namespace std;

class B0
{
public:
       virtual void display()
       {
           cout<<"this is B0 function"<<endl; 
       }      
};

class B1:public B0
{
public:
       void display()
       {
           cout<<"this is B1 function"<<endl; 
       }      
};

class B2:public B1
{
public:
       void display()
       {
           cout<<"this is B2 function"<<endl; 
       }      
};

void fun(B0 *ptr)
{
   ptr->display();     
}

int main()
{
    B0 b0 ,*p0;
    B1 b1 ,*p1;
    B2 b2 ,*p2;
    
    p0=&b0;
    fun(p0);
    p1=&b1;    
    fun(p1);
    p2=&b2;
    fun(p2);
    
    p0 = &b0;
    fun(p0);
    p0 = &b1;
    fun(p0);
    p0 = &b2;
    fun(p0);
    system("pause");
    return 0 ;
}





